DEW.DetailsController = function() {};

$.extend(DEW.DetailsController.prototype, {
    render: function() {
        DEW.ViewManager.removeAll();
        this.displayLayout();
        this.displayHeader();
        this.displayBody();
       
    },

    displayLayout: function() {
        var detailsLayout = new DEW.DetailsLayout();
        detailsLayout.render();
        $(detailsLayout.el).appendTo("#content");
        DEW.ViewManager.addView(detailsLayout);
    },

    displayHeader: function() {
        var header = new DEW.Header();
        header.render();
        /* $(header.el).appendTo("#header"); */
        $("#header").html(header.el);
        
       var loginController = new DEW.LoginController();        
        $("#btnLogin").click(function(){
            DEW.ViewManager.remove(body);
            loginController.render();
             $(".page-content").html(loginController.el);
            DEW.ViewManager.addView(loginController);
        });
        
        var registerController = new DEW.RegisterController();        
        $("#btnResgistrate").click(function(){
            debugger;
            DEW.ViewManager.remove(body);
            registerController.render();
            $(".page-content").html(registerController.el);
            DEW.ViewManager.addView(registerController);
        });
        
        var finderController = new DEW.FinderController();
        $("#btnTipoCocina").click(function(){
            debugger;
            DEW.ViewManager.remove(body);
        finderController.render();       
        /* $(body.el).appendTo(".page-content"); */
        $(".page-content").html(finderController.el);      
        DEW.ViewManager.addView(finderController);
        });
        DEW.ViewManager.addView(header);
    },

    displayBody: function() {
        var listCollection = DEW.StoreManager.get('listCollection');
        if (listCollection === null) {
            listCollection = new DEW.ListCollection();
            listCollection.fetch({reset:true});
            listCollection.on('reset',function() {
                var itemModel = listCollection.getItem(DEW.itemID).toJSON();
                var itemView = new DEW.Item({
                    model: itemModel
                });
                itemView.render();
                $(itemView.el).appendTo(".page-content");
                DEW.ViewManager.addView(itemView);
            });
        } else {
            //Para mejorar la velocidad no recargo todo sino que reutilizo el codigo
            var itemModel = listCollection.getItem(DEW.itemID).toJSON();
            var itemView = DEW.Item({
                model: itemModel
            });
            itemView.render();
            $(itemView.el).appendTo(".page-content");
            DEW.ViewManager.addView(itemView);
        }
    }

   

});